<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>3332：旧试题</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">旧试题</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">旧试题</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                旧试题                </h1>
                <p>时间限制：10s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><p><span style="font-size: medium">圣诞节将至。一年一度的难题又摆在wyx面前&mdash;&mdash;如何给妹纸送礼物。<br />
wyx的后宫有n人，这n人之间有着复杂的关系网，相互认识的人有m对。wyx想要量化后宫之间的亲密度，于是准备给每对认识关系估一个亲密度。亲密度是个正整数，值越大说明越亲密。当然有可能有些后宫之间不直接认识，为此wyx定义了一个值f(i,j)，代表从第i个后宫开始不断经过认识的人到j，经过的亲密度最小的一对关系的最大值。不过也有可能有些后宫的朋友圈互相独立，怎么也没法通过认识的人互相到达，那么f(i,j)就为-1。<br />
举个例子，wyx的后宫有4人，编号为1~4。后宫1和2之间的亲密度为3，后宫2和3之间的亲密度为4，后宫1和3之间的亲密度为2，后宫4由于不明原因被孤立了。那么f(1,2)=f(1,3)=3，f(2,3)=4，f(1,4)=f(2,4)=f(3,4)=-1。<br />
wyx认为了解后宫之间的亲密程度对于他选择礼物有着很重大的意义，于是他找了几个路人，测出了所有后宫之间的f(i,j)值。不过wyx怀疑路人在坑爹，他想知道，是否能找到一组后宫之间的亲密度方案满足路人测出的f(i,j)值？由于他还要去把妹，这个问题就交给你了。</span></p>
<p><span style="font-size: medium"><br />
</span></p></p><hr/><h3>输入格式</h3><p><p><span style="font-size: medium">第一行一个正整数T，代表数据组数。</span></p>
<p><span style="font-size: medium">接下来T组数据，每组数据第一行两个正整数n、m，代表点数和边数。</span></p>
<p><span style="font-size: medium">接下来m行，每行两个正整数代表一条边。<br />
接下来n行每行n个整数，代表所有的f(i,j)值。</span></p></p><hr/><h3>输出格式</h3><p><p><span style="font-size: medium">对于每组数据，输出 &quot;Yes&quot; 或者 &quot;No&quot;。（详细参看样例输出）</span></p></p><hr/><h3>样例输入</h3><pre>


3
4 5
1 2
1 3
1 4
2 3
2 4
0 5 5 5
5 0 5 5
5 5 0 4
5 5 4 0
4 4
1 2
1 3
2 3
2 4
0 4 4 4
4 0 4 5
4 4 0 4
4 5 4 0
4 2
1 2
2 3
0 3 3 -1
3 0 4 -1
3 4 0 -1
-1 -1 -1 0

 

</pre><hr/><h3>样例输出</h3><pre>
Case #1: No

Case #2: Yes

Case #3: Yes

 </pre><hr/><h3>提示</h3><p><p></p>
<p>数据范围</p>
<p>T &le; 30</p>
<p>n &le; 1000</p>
<p>m &le; 300000</p>
<p>f(i,j)=-1 或者 1 &le; f(i,j) &le; 32767</p>
<p>注意输入量奇大无比！<br />
</p></p><hr/><h3>题目来源</h3><p>kanari提供题面和标程，zhonghaoxi提供数据
</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=3332" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=3332" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>